package com.test.springboot.controller;

import com.test.springboot.domain.User;
import com.test.springboot.service.UserService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class UserController {

	@Resource
	private UserService userService;
	
	@RequestMapping("/common/login")
	public String login(String username,String password, HttpServletRequest request){
		User user = new User();
		user.setUsername(username);
		user.setPwd(password);
		User login = userService.login(user);
		if(login==null){
			return "账号或者密码不正确！";
		}
		
		request.getSession().setAttribute("user", login);
		return "欢迎"+login.getNickname()+"回来";
	}
	
	@RequestMapping("/admin/user/info/{id}")
	public String getUserInfo(@PathVariable("id") Integer id){
		User user = userService.getUser(id);
		
		return user.toString();
	}
}
